﻿using KwaiXiaoDian.Data;
using KwaiXiaoDian.Entity.Common;
using KwaiXiaoDian.Entity.DO;
using KwaiXiaoDian.IDao;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SSharing.Frameworks.NetCore.Common.Extends;
using System.Linq.Expressions;

namespace KwaiXiaoDian.Dao
{
    /// <summary>
    /// 
    /// </summary>
    public class ChannelDao : BaseDao<TChannel>, IChannelDao
    {
        private readonly KwaiXiaoDianDbContext _kwaiXiaoDianDbContext;

        public ChannelDao(KwaiXiaoDianDbContext kwaiXiaoDianDbContext) : base(kwaiXiaoDianDbContext)
        {
            _kwaiXiaoDianDbContext = kwaiXiaoDianDbContext;
        }

        /// <summary>
        /// 获取Channel列表依据ChannelId
        /// </summary>
        /// <param name="channelIds"></param>
        /// <returns></returns>
        public IList<TChannel> GetByChannelIds(List<long> channelIds)
        {
            IList<TChannel> channels = new List<TChannel>();

            var query = _kwaiXiaoDianDbContext.TChannel.Where(p => p.IsEnabled == Enums.IsEnabledType.Y.ToString());

            //查询条件
            if (channelIds.HasValue())
            {
                query = query.Where(p => channelIds.Contains((long)p.ChannelId));
            }

            //排序
            query = query.OrderBy(p => p.Sort);

            channels = query.ToList();
            return channels;
        }


    }
}
